﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using System.Messaging;
using System.Configuration;


namespace TPTecnicas.MessageProcessor.Processor
{
    partial class MessageProcessor : ServiceBase
    {
        private ServiceHost _serviceHost;

        public MessageProcessor()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            var queueEmailName = ConfigurationManager.AppSettings["queueEmailName"];

            if (_serviceHost != null)
            {
                _serviceHost.Close();
            }

            if (!MessageQueue.Exists(queueEmailName))
                MessageQueue.Create(queueEmailName, true);

            try
            {
                _serviceHost = new ServiceHost(typeof(Services.MessageProcessorService));
                _serviceHost.Open();
            }
            catch (Exception ex)
            {

            }
        }

        protected override void OnStop()
        {
            try
            {
                _serviceHost.Close();
            }
            catch (Exception ex)
            {

            }
        }
    }
}
